﻿ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL.Page;
using GCELibrary.Current;

 
namespace ZF.WS
{
    public partial class Login : LoginPage
    {

   
        protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.tbAccount.Text) && !string.IsNullOrEmpty(this.tbPwd.Text))
                {
#if(l)
                    if (SiteInfo.IsLocal)
                    {
                        _login(this.tbAccount.Text.Trim(), this.tbPwd.Text);
                        return;
                    }
#endif


                    if (SiteInfo.ValidateCode(this.tbVCode.Text))
                    {
                        _login(this.tbAccount.Text.Trim(), this.tbPwd.Text);
                    }
                    else
                    {
                        WarnFactory.CreateWarn(new GCELibrary.Current.PageWarnParameter()
                        {

                            JscriptMode = true,
                            Message = "验证码错误",
                            Link = WarnLink.GoBack,
                        }).Alert();
                    }

                    
                }
                else if (Request.Form["account"] != null && Request.Form["password"] != null)
                {
                    _login(Request.Form["account"], Request.Form["password"]);
                }
            }
            else
            {
#if(l)
                if (SiteInfo.IsLocal)
                {
                    this.tbAccount.Text = "aoxin";
                    this.tbPwd.Attributes["value"] = "123456";
                }
#endif
            }


        }
        protected void _Login(object sender, EventArgs e)
        {

        }

        private void _login(string account,string pwd)
        {
            var gate = new BLL.Gate.GeneralGate();

            if (!string.IsNullOrEmpty(this.from))
            {
                gate.DefaultPage = this.from;
            }
            gate.Login(account, pwd, this.cbRemember.Checked ? 30 : -1);
        }
    }
}
